project('cache simulator', 'cpp', default_options: [
    'cpp_std=c++14',
    'optimization=3'
], version: '0.1.2')

verbose = false
add_project_arguments('-DSLOG_ENABLE', '-DSASSERT_ENABLE', language : 'cpp')
incdir = include_directories('contrib', 'src')

glob = 'tools/meson-glob.sh'

# src
objs = []
src = run_command(glob, 'd', 'src', check: true).stdout().strip()
if src != ''
    foreach i: src.split('\n')
        # message(i)
        s = run_command(glob, 's', 'src' / i, check: true).stdout().strip()
        if s != ''
            objs += static_library(i, s.split('\n'), include_directories: incdir)
        endif
    endforeach
endif

# examples
eg = run_command(glob, 'e', 'examples', check: true).stdout().strip()
if eg != ''
    foreach i: eg.split('\n')
        v = i.split(',') # [exec, dir]
        executable(v[0], [v[1] / v[0] + '.cpp'], link_with: objs, install_dir: v[1],
            install: true, include_directories: incdir)
    endforeach
endif

# scratch
sc = run_command(glob, 'e', 'scratch', check: true).stdout().strip()
if sc != ''
    foreach i: sc.split('\n')
        v = i.split(',') # [exec, dir]
        executable(v[0], [v[1] / v[0] + '.cpp'], link_with: objs, install_dir: v[1],
            install: true, include_directories: incdir)
    endforeach
endif
